﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Xml;

namespace CodeGame
{

    static class ConfigManager
    {
        public static int WindowWidth;
        public static int WindowHeight;

        public static void LoadConfig(string filename)
        {
            XmlReader reader = XmlReader.Create(filename);

            while (reader.Read())
            {
                switch (reader.Name)
                {
                    case "config":

                        break;
                    case "display":
                        ConfigManager.WindowWidth = Convert.ToInt32(reader.GetAttribute("width"));
                        ConfigManager.WindowHeight = Convert.ToInt32(reader.GetAttribute("height"));
                        break;
                    case "uiNormal":
                        Singletons.NormalText = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b"))
                            );
                        break;
                    case "uiError":
                        Singletons.ErrorText = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b"))
                            );
                        break;
                    case "uiEntry":
                        Singletons.EntryText = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b"))
                            );
                        break;
                    case "uiOldEntry":
                        Singletons.OldEntryColor = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b"))
                            );
                        break;
                    case "gameBackground":
                        Singletons.Background = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b"))
                            );
                        break;
                    case "network":
                        Singletons.NetworkColor = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b"))
                            );
                        break;
                    case "window":
                        Singletons.WindowColor = new Microsoft.Xna.Framework.Color(
                                Convert.ToInt32(reader.GetAttribute("r")),
                                Convert.ToInt32(reader.GetAttribute("g")),
                                Convert.ToInt32(reader.GetAttribute("b")),
                                Convert.ToInt32(reader.GetAttribute("a"))
                            );
                        break;
                    default:
                        break;
                }


            }

            reader.Close();
        }

        public static void LoadConfig()
        {
            ConfigManager.LoadConfig("config.xml");
        }

    }
}
